<template>
    <div>
        <h1>房号修改</h1>
        <table class="table table-bordered">
            <tr>
                <td>房号名称</td>
                <td>
                    <input type="text" v-model="fh.name">
                </td>
            </tr>

            <tr>
                <td>房型</td>
                <td>
                    <select v-model="fh.housex">
                        <option value="">请选择</option>
                        <option value="商务型">商务型</option>
                        <option value="豪华型">豪华型</option>
                        <option value="标准型">标准型 </option>

                    </select>
                </td>
            </tr>

            <tr>
                <td>房态</td>
                <td>
                    <select v-model="fh.houset">
                        <option value="">请选择</option>
                        <option value="空闲">空闲</option>
                        <option value="入住">入住</option>
                        <option value="维修">维修</option>

                    </select>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="房号修改" @click="addn">
                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import axios from 'axios';
let router = useRouter();
let route = useRoute();

let data: any = reactive({
    fh: {
        "name": "",
        "housex": "",
        "houset": "",

    },
});
let { fh } = toRefs(data);

const addn = () => {
    let obj = {
        id: route.query.id,
        name: fh.value.name,
        housex: fh.value.housex,
        houset: fh.value.houset,
    };
    if (obj.name == "") {
        alert("请输入房号");
        return;
    }
    if (obj.housex == "") {
        alert("请输入房型");
        return;
    }
    if (obj.houset == "") {
        alert("请输入房态");
        return;
    }
    axios({
        url: '/api/HousN/Update',
        method: 'put',
        data: obj,
    }).then((res) => {
        if(res.data.data == -1)
    {
        alert('房号已存在');
        return;
    }
        else if (res.data.data == 1) {
            alert('修改成功');
            router.push('/listn');
        } else {
            alert('修改失败');
            return;
        }
    })
}

const FanTian=()=>{
    let obj={
        id:route.query.id,
    }
    axios({
        url: '/api/HousN/FanTian',
        method: 'get',
        params: obj,
    }).then((res) => {
        fh.value=res.data.data;
    })
}

onMounted(()=>{
    FanTian();
})
</script>

<style scoped></style>